package tests;

import common.Utils;
import org.openqa.selenium.By;

public class EditPage extends Utils {
    public static String url ="http://8.137.19.140:9090/blog_edit.html";
    public EditPage() {
        super(url);
    }
    //未登录状态下正常打开
    public void ByNoLoginRight(){
        driver.findElement(By.cssSelector("#submit"));
    }

    //未登录状态发布博客，跳转到登录页
    public void ByNoLoginPublish() throws InterruptedException {
        String blogTitle = "自动化测试";
        driver.findElement(By.cssSelector("#title")).sendKeys(blogTitle);
        driver.findElement(By.cssSelector("#submit")).click();
    }

    //登录状态下发布博客
    public void ByLoginPublish() throws InterruptedException {
        driver.findElement(By.cssSelector("#username")).sendKeys("zhangsan");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");
        driver.findElement(By.cssSelector("#submit")).click();
        driver.findElement(By.cssSelector("body > div.nav > a:nth-child(5)")).click();
        String blogTitle = "自动化测试";
        driver.findElement(By.cssSelector("#title")).sendKeys(blogTitle);
        driver.findElement(By.cssSelector("#submit")).click();
        Thread.sleep(3000);
        driver.findElement(By.cssSelector("#username")).sendKeys("zhangsan");
        driver.findElement(By.cssSelector("#password")).sendKeys("123456");
        driver.findElement(By.cssSelector("#submit")).click();

        String title = driver.findElement(By.cssSelector("body > div.container > div.right > div:nth-child(905) > div.title")).getText();
        assert title.equals(blogTitle);

    }
}
